﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Krypton.Toolkit;
using ScottPlot.Styles;
using Serilog.Core;
using TSNPro.Utils;

namespace TSNPro.MyForm
{
    public partial class FormLog : KryptonForm
    {
        private FormLog()
        {
            InitializeComponent();

            // 假设 Logger 是一个单例类，你需要提供一个事件或回调来接收日志消息
            LogTextWriter.GetInstance().OnLogging += Log;
            TopMost = true;
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }

        // 日志输出方法
        public void Log(object sender, string log)
        {
            // 将日志追加到 TextBox 中
            txtLog.AppendText(log + Environment.NewLine);

            // 限制行数，如果行数超过 500 行，清除所有文本
            if (txtLog.Lines.Length > 1000)
            {
                txtLog.Clear();
            }
        }

        private static FormLog _instance;
        private static readonly object _lock = new object();
        public static FormLog GetInstance()
        {
            lock (_lock)
            {
                if (_instance == null)
                {
                    _instance = new FormLog();
                }
                return _instance;
            }
        }
    }
}
